package br.com.onlinebidding.controller;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;

import br.com.onlinebidding.dao.UserDAO;
import br.com.onlinebidding.entity.User;

@ManagedBean
@SessionScoped
public class UserController {
	private User user = new User();
	private DataModel<User> users;

	public List<User> getAll() {
		List<User> list = UserDAO.getAll();
		return list;
	}

	public User getUser() {
		return this.user;

	}

	public void setUser(User u) {
		this.user = u;
	}

	public String prepareToAddUser() {
		this.user = new User();
		return "/view/private/user/form-user";
	}

	public String prepareToEdictUser() {
	System.out.print("Entrou no prepareToEdictUser");
		this.user = this.users.getRowData();
		return "/view/private/user/edict-user";
	}

	public String deleteUser() {
		System.out.print("Entrou no deleteUser");
		User temp = this.users.getRowData();
		UserDAO.delete(temp);
		return "/view/private/user/list-user";
	}

	public String addUser() {
		UserDAO.insert(this.user);
		user = new User();
		return "/view/private/user/list-user";
	}

	public String updatetUser() {
		UserDAO.update(this.user);
		return "/view/private/user/list-user";
	}
	
	public String login(){
		user = new User();
		return "/view/public/main";
	}
}
